app.controller('StartModalCtrl', function ($scope, $modalInstance, toaster, param, ajax) {

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	$scope.apilist = [];

	//接口列表读取
	$scope.loadApiList = function () {
		ajax.call(new Req.GET({
			resource: 'apiconf/list'
		})).then(function (result) {
			$scope.apilist = result.result;
			//设置默认值
			if ($scope.param.data.apiId != undefined) {
				var id = $scope.param.data.apiId;
				var sel = 0;
				for (var i = 0; i < $scope.apilist.length; i++) {
					sel++;
					if ($scope.apilist[i].id == id) {
						break;
					}
				}

				$scope.apilist.selected = $scope.apilist[sel - 1];
			} else {
				$scope.apilist.selected = $scope.apilist[0];
			}

		}, function () { });
	};
	$scope.loadApiList();

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			$scope.param.data.apiId = $scope.apilist.selected.id;
			$modalInstance.close($scope.param);
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});